var ns, toast, actionsheet;
var app = new Vue({
    el: '#app',
    data: {
        form: {
            CNamesDesc:'',
            ProjectNames:'',
            BusinessTime:'',
        },
    },
    methods: {
        get_data:function() {
            var that = this;
            var option = {};
            option.action = "getbusinessinfo";
            ns.post(option, function(succeed, data, err) {
                console.log(JSON.stringify(data));
                if (succeed) {
                    that.form = data.BusinessInfo;
                    that.form.CNamesDesc=data.BusinessInfo.CNamesDesc.toString();
                    that.form.ProjectNames=data.BusinessInfo.ProjectNames.toString();
                    that.form.BusinessTime=data.BusinessInfo.BusinessHoursStart+'~'+data.BusinessInfo.BusinessHoursEnd;
                }
            });
        },
        // 商品上下架
        product_up:function(){
            var that=this;
            if(that.form.Status==3){
                that.$dialog.confirm({
                    title: '下架提示',
                    message: '商家下架后，买家无法下单，商城不会显示商家、商品信息。确认要下架吗？',
                    confirmButtonText:'确认下架',
                    cancelButtonText:'取消下架',
                }).then(() => {
                    var option = {};
                    option.action = "downbusiness";
                    ns.post(option, function(succeed, data, err) {
                        console.log(JSON.stringify(data));
                        if (succeed) {
                            api.toast({
                                msg: data,
                                duration: 2000,
                                location: 'bottom'
                            });
                           that.get_data();
                        }else{
                            api.toast({
                                msg: '下架失败',
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                     });
                }).catch(() => {
                    // on cancel
                  });
            }else if(that.form.Status==1){
                that.$dialog.confirm({
                    title: '提示信息',
                    message: '确定要提交商家上架申请吗？',
                    confirmButtonText:'确认上架',
                    cancelButtonText:'暂不上架',
                }).then(() => {
                    var option = {};
                    option.action = "upbusiness";
                    ns.post(option, function(succeed, data, err) {
                        console.log(JSON.stringify(data));
                        if (succeed) {
                            api.toast({
                                msg: '上架成功',
                                duration: 2000,
                                location: 'bottom'
                            });
                            that.get_data();
                        }else{
                            api.toast({
                                msg: '上架失败',
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                     });

                }).catch(() => {
                });
            }else{
                api.toast({
                    msg: '该状态不支持上下架',
                    duration: 2000,
                    location: 'bottom'
                });
            }
       
        },
        //商家是否营业
        shop_up:function(){
            var that=this;
            if(that.form.PublishStatus==1){
                that.$dialog.confirm({
                    title: '提示信息',
                    message: '暂停营业后，买家无法正常下单，确定要暂停营业吗？',
                    confirmButtonText:'确认暂停',
                    cancelButtonText:'取消',
                }).then(() => {
                    var option = {};
                    option.action = "togglebusinesspublishstatus";
                    option.PublishStatus=that.form.PublishStatus;
                    ns.post(option, function(succeed, data, err) {
                        console.log(JSON.stringify(option));
                        console.log(JSON.stringify(data));
                        if (succeed) {
                            api.toast({
                                msg: '操作成功',
                                duration: 2000,
                                location: 'bottom'
                            });
                            that.get_data();
                        }else{
                            api.toast({
                                msg: '操作失败',
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                     });

                }).catch(() => {
                });
            }else{
                that.$dialog.confirm({
                    title: '提示信息',
                    message: '确定要开始营业吗？',
                    confirmButtonText:'开始营业',
                    cancelButtonText:'暂不营业',
                }).then(() => {
                    var option = {};
                    option.action = "togglebusinesspublishstatus";
                    option.PublishStatus=that.form.PublishStatus;
                    ns.post(option, function(succeed, data, err) {
                        console.log(JSON.stringify(option));
                        console.log(JSON.stringify(data));
                        if (succeed) {
                            api.toast({
                                msg: '操作成功',
                                duration: 2000,
                                location: 'bottom'
                            });
                            that.get_data();
                        }else{
                            api.toast({
                                msg: '操作失败',
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                     });

                }).catch(() => {
                });
            }
        },

        // 编辑商家基本信息
        do_openshopedit(){
            if(this.form.Status==3){
                this.$dialog.alert({
                    title: '编辑提示',
                    message: '商家已上架，编辑信息需要下架后才能继续操作。',
                }).then(() => {
                    return;
                });
            }else{
                ns.openWin('shopmsg_edit', '商家信息编辑');
            }
        },
        // 收款账户编辑
        do_shopeditkey:function(item){
            var that=this;
            ns.openWin('shopkey_edit', '收款账户编辑',{
                item:item
            });
        },
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    toast = new auiToast();
    actionsheet = new auiActionsheet();
    app.get_data();
    api.addEventListener({
        name: 'edit_shop'
    }, function(ret, err) {
        app.get_data();
    });
};
